/*     */ package com.zimbra.cs.security.sasl;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.auth.AuthContext.Protocol;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.security.sasl.SaslServer;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PlainAuthenticator
/*     */   extends Authenticator
/*     */ {
/*     */   public static final String MECHANISM = "PLAIN";
/*     */   
/*     */   public PlainAuthenticator(AuthenticatorUser user)
/*     */   {
/*  39 */     super("PLAIN", user);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected boolean isSupported()
/*     */   {
/*  46 */     return (this.mAuthUser.isSSLEnabled()) || (this.mAuthUser.allowCleartextLogin());
/*     */   }
/*     */   
/*  49 */   public boolean initialize() { return true; }
/*     */   
/*     */   public void dispose() {}
/*  52 */   public boolean isEncryptionEnabled() { return false; }
/*     */   
/*  54 */   public InputStream unwrap(InputStream is) { return null; }
/*  55 */   public OutputStream wrap(OutputStream os) { return null; }
/*     */   
/*  57 */   public SaslServer getSaslServer() { return null; }
/*     */   
/*     */   public void handle(byte[] data) throws IOException {
/*  60 */     if (isComplete()) {
/*  61 */       throw new IllegalStateException("Authentication already completed");
/*     */     }
/*     */     
/*     */ 
/*  65 */     String message = new String(data, "utf-8");
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  73 */     int nul1 = message.indexOf(0);int nul2 = message.indexOf(0, nul1 + 1);
/*  74 */     if ((nul1 == -1) || (nul2 == -1)) {
/*  75 */       sendBadRequest();
/*  76 */       return;
/*     */     }
/*  78 */     String authorizeId = message.substring(0, nul1);
/*  79 */     String authenticateId = message.substring(nul1 + 1, nul2);
/*  80 */     String password = message.substring(nul2 + 1);
/*  81 */     authenticate(authorizeId, authenticateId, password);
/*     */   }
/*     */   
/*     */   public Account authenticate(String username, String authenticateId, String password, AuthContext.Protocol protocol, String origRemoteIp, String remoteIp, String userAgent)
/*     */     throws ServiceException
/*     */   {
/*  87 */     Provisioning prov = Provisioning.getInstance();
/*  88 */     Account authAccount = prov.get(Key.AccountBy.name, authenticateId);
/*  89 */     if (authAccount == null) {
/*  90 */       ZimbraLog.account.info("authentication failed for " + authenticateId + " (no such account)");
/*  91 */       return null;
/*     */     }
/*     */     
/*     */ 
/*  95 */     Map<String, Object> authCtxt = new HashMap();
/*  96 */     authCtxt.put("ocip", origRemoteIp);
/*  97 */     authCtxt.put("remoteip", remoteIp);
/*  98 */     authCtxt.put("anp", authenticateId);
/*  99 */     authCtxt.put("ua", userAgent);
/* 100 */     prov.authAccount(authAccount, password, protocol, authCtxt);
/*     */     
/* 102 */     return authorize(authAccount, username, true);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/security/sasl/PlainAuthenticator.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */